require 'java'

# Include a Java class, only if it's not already defined
def friendly_class c
  classname = c[/\w+$/]
  begin
    Kernel.const_get(classname)
    puts "Class #{classname} already defined" if $DEBUG
  rescue
    begin
      include_class c
    rescue
      puts "Failed to load class #{c}: #{$!}"
      puts "(Please confirm that you are running with jruby and that the Processing core.jar is in your CLASSPATH environment variable.)"
      # TODO: Munge ENV['CLASSPATH'] ourselves and try to locate the 
      # libraries in pwd or PATH or something someday?
      return false
    end
  end
  return true
end


